package org.testing.ui;

import java.util.List;

import org.testing.InOutManager;
import org.testing.QuestionsMaker;
import org.testing.model.Test;
import org.testing.model.results.Result;

public class ConsoleInterface {
	public static final int QUESTIONS_FOR_TEST = 4;
	
	public static void main(String[] args) {
		
		
		InOutManager inOut = new InOutManager(System.in, System.out);
		Test myPrivateTest = new Test(inOut);
		QuestionsMaker teacher = new QuestionsMaker();
		myPrivateTest.loadQuestions(teacher.getQuestionsForTest(QUESTIONS_FOR_TEST));
		List<Result> testResults;
		if  (myPrivateTest.isReadyToTest()) {
			testResults = myPrivateTest.conductTheTest();
			processResults(testResults);
		
		} 
	}
	
	private static void processResults(List<Result> resultsOfTheTest) {
		double wholeResults = 0;
		for(Result commonResult : resultsOfTheTest ) {
			wholeResults += commonResult.toDouble();
		}
		printResultToPromt(wholeResults);
	}
	
	private static void printResultToPromt(double result) {
		System.out.printf("Your result is" + "\n" + result + " of " + QUESTIONS_FOR_TEST);
	}
}
